package com.vcms.view.simulation.uicomponent.listener;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */

import java.awt.*;

import com.vcms.view.simulation.uifactory.EventArgs;
import com.vcms.view.simulation.uifactory.VMCSEventHandler;

import com.vcms.controller.storemanagement.StoreController;
import com.vcms.view.simulation.uicomponent.dialog.MessageDialog;

public class StoreViewerListener implements ActionListener,VMCSEventHandler {

	private char type;
	private int item;
	private StoreController storeCtrl;

	public StoreViewerListener(char type, int item, StoreController sctrl) {
		this.type = type;
		this.item = item;
		storeCtrl = sctrl;

	}

	public void actionPerformed(ActionEvent e) {
		/** @todo: Implement this java.awt.event.ActionListener method */
		TextField vf;
		int qty;
		String sqty;

		vf = (TextField) e.getSource();

		sqty = vf.getText();
		try {
			qty = Integer.parseInt(sqty);
		} catch (NumberFormatException ee) {
			@SuppressWarnings("unused")
			MessageDialog ms = new MessageDialog(
					storeCtrl.getMainController().getMachinaryController().getMachinerySimulatorPanel(),
					MessageDialog.NUMBER_FORMAT_ERROR);
			return;
		}

		storeCtrl.changeStoreQty(type, item, qty);
	}
	
	public void vmcsActionPerformed(Object eventSource, EventArgs args) {
		ActionEvent event = new ActionEvent(null, 0, null);
		this.actionPerformed(event);
	}
}